import {getCompanyNum} from '@/base/api/AccountApi';
import {getDevNum} from '@/base/api/DevcieApi';
import {store} from '@/store/Store';
import {toThousNumber} from '@/base/util/Strings';
import {getAgentNum} from '@/base/api/AgentApi';
import {getMemberNum} from '@/base/api/MemberApi';

export class ListHeaderBloc {
  companyNum: number = 0;
  devNum = 0;
  companyId = 0;

  totalArr = [
    {
      name: '会员数量',
      number: 0,
      class: 'b-right'
    },
    {
      name: '设备数量',
      number: 0,
      class: 'b-right'
    },
    {
      name: '经销商数量',
      number: 0,
      class: ''
    }
  ];

  load() {
    if (store.state.user.tepee === '1') {
      this.companyId = store.state.user.account.companyId || 0;
    } else {
      this.companyId = store.state.user.agent.companyId || 0;
    }
      const arr: any = [
        getMemberNum(),
        getDevNum({companyId: this.companyId}),
        getAgentNum()
      ];
      Promise.all(arr)
        .then(res => {
          this.totalArr.forEach((x, index) => {
            // @ts-ignore
            x.number = toThousNumber(res[index].data)
          });
        })
        .catch(err => {
          console.log('get failed', err);
        });
  }
}
